<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/6/9
 * Time: 10:25
 */

namespace Admin\Model;

use Think\Model;

class HospitalModel extends Model{
    protected $tableName = "shop_hospital";

    public function HospitalList(){
        $res = M("shop_hospital as h")
            ->field('h.id,h.name,c1.name as province,c2.name as city,c3.name as area')
            ->where('is_delete != 1')
            ->join("left join wp_city as c1 on c1.id = h.province")
            ->join("left join wp_city as c2 on c2.id = h.city")
            ->join("left join wp_city as c3 on c3.id = h.area")
            ->order('id desc')
            ->select();
        if(false !== $res){
            return $res;
        }
    }
    public function HospitalAdd($data){
        $data['created_time'] = time();
        $data['updated_time'] = time();
        return $this->add($data);
    }

    public function HospitalFind($id){
        if(!$id)return;
        $res = M("shop_hospital as h")
            ->where('is_delete != 1')
            ->where("h.id = %d",$id)
            ->order('id desc')
            ->find();
        return $res;
    }
    public function HospitalEdit(){
        $this->create();
        return $this->save();
    }
    public function HospitalDel($id){
        if(!$id)return;
        return $this->delete($id);
    }
}